package com.hdu.other.oneDimensionPreInfo;

public class lc303 {



    class NumArray {

        int[] preSum = null;

        public NumArray(int[] nums) {
            int len = nums.length;
            preSum = new int[len + 1];
            for (int i = 1; i <= len; i++) {
                preSum[i] = preSum[i - 1] + nums[i - 1];
            }
        }

        public int sumRange(int left, int right) {
            /**
             * 1    2    3    4    5
             *     left      right
             * sumRange(2, 4) = 2 + 3 + 4 = 9
             * preSum
             * 0    1    3    6   10  15
             * preSum[right + 1] - preSum[left]
             */
            return preSum[right + 1] - preSum[left];
        }
    }

/**
 * Your NumArray object will be instantiated and called as such:
 * NumArray obj = new NumArray(nums);
 * int param_1 = obj.sumRange(left,right);
 */

}
